package com.patrol.logisticsmanage.ui.home;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.bumptech.glide.Glide;
import com.patrol.logisticsmanage.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class NoticeAdapter extends RecyclerView.Adapter<NoticeAdapter.ViewHolder> {
    Context context;
    List<Notice> notices;

    public NoticeAdapter(Context context, List<Notice> notices) {
        this.notices = notices;
        this.context = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_notice, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.itemView.setOnClickListener(v -> ARouter.getInstance().build("/app/WebViewActivity")
                .withString("url", notices.get(position).content)
                .withString("title", notices.get(position).title)
                .withBoolean("isContent",true)
                .navigation());


        holder.tvNoticeTitle.setText(notices.get(position).title);
        Glide.with(context)
                .load(notices.get(position).getPicture())
                .centerCrop()
                .placeholder(R.drawable.food2)
                .into(holder.imgNotice);
        holder.tvNoticeSubtitle.setText("XXXXXX");
        holder.tvGoodsChange.setText(notices.get(position).catalog_dictText);
        holder.tvNoticeTime.setText(notices.get(position).updateTime);
    }

    @Override
    public int getItemCount() {
        return notices.size();
    }

    static
    class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.img_notice)
        ImageView imgNotice;
        @BindView(R.id.tv_notice_title)
        TextView tvNoticeTitle;
        @BindView(R.id.tv_notice_subtitle)
        TextView tvNoticeSubtitle;
        @BindView(R.id.tv_notice_time)
        TextView tvNoticeTime;
        @BindView(R.id.tv_goods_change)
        TextView tvGoodsChange;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
